Make gdk_surface_get_device_position return a boolean
authorMatthias Clasen <mclasen@redhat.com>
Wed, 26 Aug 2020 13:01:48 +0000 (09:01 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 26 Aug 2020 13:11:28 +0000 (09:11 -0400)
A year ago, we make this function not return the child
surface anymore. But the information whether the device
is actually over the surface is still useful, and we
should not loose it.

gdk/gdksurface.c
gdk/gdksurface.h

index cf471d49c6e26534e247952338d33b6fe2c6ed73..f89061a002be0cd49840bec9ed04b683fb561383 100644 (file)
@@ -1627,8 +1627,10 @@ gdk_surface_constrain_size (GdkGeometry    *geometry,
  * Obtains the current device position in doubles and modifier state.
  * The position is given in coordinates relative to the upper left
  * corner of @surface.
+ *
+ * Return: %TRUE if the device is over the surface
  **/
-void
+gboolean
 gdk_surface_get_device_position (GdkSurface       *surface,
                                  GdkDevice       *device,
                                  double          *x,
@@ -1637,17 +1639,20 @@ gdk_surface_get_device_position (GdkSurface       *surface,
 {
   double tmp_x, tmp_y;
   GdkModifierType tmp_mask;
+  gboolean ret;
 
-  g_return_if_fail (GDK_IS_SURFACE (surface));
-  g_return_if_fail (GDK_IS_DEVICE (device));
-  g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
+  g_return_val_if_fail (GDK_IS_SURFACE (surface), FALSE);
+  g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
+  g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
 
-  tmp_x = tmp_y = 0;
+  tmp_x = 0;
+  tmp_y = 0;
   tmp_mask = 0;
-  GDK_SURFACE_GET_CLASS (surface)->get_device_state (surface,
-                                                     device,
-                                                     &tmp_x, &tmp_y,
-                                                     &tmp_mask);
+
+  ret = GDK_SURFACE_GET_CLASS (surface)->get_device_state (surface,
+                                                           device,
+                                                           &tmp_x, &tmp_y,
+                                                           &tmp_mask);
 
   if (x)
     *x = tmp_x;
@@ -1655,6 +1660,8 @@ gdk_surface_get_device_position (GdkSurface       *surface,
     *y = tmp_y;
   if (mask)
     *mask = tmp_mask;
+
+  return ret;
 }
 
 /**
index 9b1613147f2ec9bc35ce7d30ffe8f7ff501d0bb6..a03b02a4e32ced016910bc1a886b127ab06af40c 100644 (file)
@@ -187,7 +187,7 @@ GDK_AVAILABLE_IN_ALL
 int           gdk_surface_get_scale_factor  (GdkSurface     *surface);
 
 GDK_AVAILABLE_IN_ALL
-void          gdk_surface_get_device_position (GdkSurface      *surface,
+gboolean      gdk_surface_get_device_position (GdkSurface      *surface,
                                                GdkDevice       *device,
                                                double          *x,
                                                double          *y,